package org.poliglot.syllab.tex;

import net.davidashen.text.Hyphenator;
import org.poliglot.syllab.HyphenatorEngine;

import java.io.IOException;
import java.io.InputStream;


/**
 * User: cristi
 * Date: 23.04.2010
 * Time: 15:45:46
 */
public class TexHyphenator implements HyphenatorEngine
{
    Hyphenator hyphenator;

    public TexHyphenator( InputStream table )
    {
        hyphenator = new Hyphenator();

        try
        {
            hyphenator.loadTable( table );
        }
        catch ( IOException e )
        {
            throw new RuntimeException( e );
        }
    }

    public String hyphenate( String source )
    {
        return hyphenator.hyphenate( source ).replace( ( char ) 173, '-' );
    }
}
